Dynamical Geometric: Sc_euclidean

  INTERFACE TRANS
     MODULE PROCEDURE transR(A,X,b,EXACT,ctime) ! CTIME=TRUE EXACT=FALSE -> SIXTRACK
     MODULE PROCEDURE transp
     MODULE PROCEDURE TRANSP_P   ! New stuff
     MODULE PROCEDURE transS
     MODULE PROCEDURE TRANSS_S   ! New stuff
  END INTERFACE


  INTERFACE ROT_XZ
     MODULE PROCEDURE ROT_XZR      ! PROT FOR MISALIGNMENT AND PATCHES   X->Z
     MODULE PROCEDURE ROT_XZP
     MODULE PROCEDURE ROT_XZP_P
     MODULE PROCEDURE ROT_XZS
     MODULE PROCEDURE ROT_XZS_S
  END INTERFACE

  INTERFACE ROT_YZ         
     MODULE PROCEDURE ROT_YZR     ! PROT FOR MISALIGNMENT AND PATCHES   Y->Z
     MODULE PROCEDURE ROT_YZP
     MODULE PROCEDURE ROT_YZP_P
     MODULE PROCEDURE ROT_YZS
     MODULE PROCEDURE ROT_YZS_S
  END INTERFACE

  INTERFACE ROT_XY
     MODULE PROCEDURE ROT_XYR    ! X->Y
     MODULE PROCEDURE ROT_XYP
     MODULE PROCEDURE ROT_XYP_P
     MODULE PROCEDURE ROT_XYS
     MODULE PROCEDURE ROT_XYS_S
  END INTERFACE



Purely Geometric: Sd_frame

      COMPUTE_ENTRANCE_ANGLE(ENTL,ENTB,A)    ENTB= "R(A(1)) R(A(2)) R(A(3))" ENTL

      FIND_PATCH_B(A,ENT,B,EXI,D,ANG)     ! FIND PATCH NECESSARY TO GO FROM (A,ENT) TO (B,EXI) IN PTC ORDER
       
      ROTATE_FRAME(R,OMEGA,ANG,->ORDER,BASIS)  !ROTATING THE MAGNET_FRAME R IN PTC ORDER=1,-1  
      
      TRANSLATE_FRAME(R,D,->ORDER,BASIS)       !ROTATING THE MAGNET_FRAME R  ORDER=-1 MEANS INVERSE OF D
       
      change_basis(A,ENT,B,EXI)     !  V ARE COMPONENTS IN GLOBAL_BASIS V=A*ENT = B*EXI   OUTPUT IS B

      GEO_TRA(A,ENT,D,I)    ! A= A +I D*ENT     I=1,-1     
                           ! D IS IN THE ENT BASIS AND THE RESULT IS IN THE GLOBAL FRAME
      GEO_ROTB(ENT,EXI,A,B,ANG,->BASIS) 
                           ! rotates (ENT,A) into (EXI,B) by ANG defined in BASIS in the PTC order 
      GEO_ROTAB_no_vec(ENT,EXI,ANG,->BASIS)     ! calls above  with a=b=0

      GEO_ROTA(ENT,A,ANG,I,->basis)  !Rotate ENT,A using ANG in the PTC order using basis
                                    ! i=-1  reverse order and negative angle
       GEO_ROTA_no_vec(ENT,ANG,I,->basis) ! same as above a=0

Layout Geometric: Sl_family     (DO NOT APPLY TO INTEGRATION_NODE)
Example: 
 call translate(ARC12b2,d)
  INTERFACE TRANSLATE
     MODULE PROCEDURE TRANSLATE_layout(R,D,->I1,I2,ORDER,BASIS)
     MODULE PROCEDURE TRANSLATE_fibre(R,D,->ORDER,BASIS) 
     MODULE PROCEDURE TRANSLATE_frame(R,D,->ORDER,BASIS) 
  END  INTERFACE


   (R,D,I1,I2,ORDER,BASIS) =>  R=LAYOUT  D(3)=TRANSLATION  (FROM I1 TO I2 INCLUSIVE)

    ORDER=1 => T(1) T(2) T(3)   ORDER=-1 => -T(1) -T(2) -T(3)

    BASIS=P%MAG%P%F%ENT


  INTERFACE ROTATE
     MODULE PROCEDURE ROTATE_LAYOUT(R,OMEGA,Ang,->I1,I2,ORDER,BASIS)
     MODULE PROCEDURE ROTATE_FIBRE(R,OMEGA,Ang,->ORDER,BASIS)
     MODULE PROCEDURE ROTATE_FRAME->(R,OMEGA,Ang,->ORDER,BASIS) !LOCATED IN SD_FRAME
  END  INTERFACE

 OMEGA(3)= POINT OF ROTATION
 ANG(3)=ANGLES
 X ROTATION MEANS Y-AXIS GOES INTO Z 
 Y ROTATION MEANS X-AXIS GOES INTO Z 
 Z ROTATION MEANS X-AXIS GOES INTO Y

  INTERFACE SURVEY
     MODULE PROCEDURE SURVEY_FIBRE(C,ENT,A,->SKIP,E_IN)
     MODULE PROCEDURE SURVEY_EXIST_PLANAR_IJ(PLAN,I1,I2,->ENT,A) ! ENT AND A ALMOST NEVER USED.
     MODULE PROCEDURE SURVEY_EXIST_PLANAR_I (PLAN,I1,->ENT,A)   !ONE TURN AROUND OF THE ABOVE; ENT AND A ALMOST NEVER USED.
     MODULE PROCEDURE SURVEY_EXIST_PLANAR_L_NEW (PLAN,->ENT,A)   ! ONE TURN AROUND FROM BEGINNING; ENT AND A ALMOST NEVER USED.
  END INTERFACE

  
SURVEY_FIBRE:

CALL SURVEY(P,ENT,A)   TRACKS ENT(3,3) AND A(3) THROUGH THE FIBRE  N.B. ENT,A ARE OVERWRITTEN
              DIR=1  (ENT,A) THROUGH FRONTAL PATCH, CHART%F%ENT, MAGNET, CHART%F%EXI, BACK PATCH 
              DIR=-1 (ENT,A) THROUGH BACK PATCH, CHART%F%EXI, MAGNET, CHART%F%ENT, FRONTAL PATCH

SURVEY_EXIST_PLANAR_IJ(PLAN,I1,I2,->ENT,A)    ENT AND A ALMOST NEVER USED. 

    SURVEYS FROM POSITION I1 TO I2 INCLUSIVE STARTING WITH 
          IF(C%DIR==1) THEN
             ENT=C%CHART%F%ENT
             A=C%CHART%F%A
          ELSE
             ENT=C%CHART%F%EXI
             A=C%CHART%F%B
          ENDIF

$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

MISALIGN_FIBRE(S2,S1,->OMEGA,BASIS)  OVERWRITES EXISTING MISALIGNMENTS

S2=> FIBRE
S1(1:3)=TRANSLATION  
S1(4:6)= ANGLES IN PTC ORDER  ---->  R(1)R(2)R(3) T
OMEGA=PIVOT POINT
BASIS

MAD_MISALIGN_FIBRE(S2,S1)

MISALIGN_SIAMESE(S2,S1,OMEGA,BASIS) ---> MISALIGNS A FULL CIRCULAR LINKED LIST OF MAGNETS

MAG1%SIAMESE=>MAG2
MAG2%SIAMESE=>MAG3
  .
  .
  .
MAGN%SIAMESE=>MAG1

$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$

  INTERFACE FIND_PATCH
     MODULE PROCEDURE FIND_PATCH_0
  END INTERFACE

FIND_PATCH_P_new(EL1,EL2_NEXT,D,ANG,DIR,ENERGY_PATCH,PREC) 

 CHECK_NEED_PATCH(EL1,EL2_NEXT,PREC,PATCH_NEEDED) ! check need of  PATCHES
prec=1.d-10  if >prec, patch needed
PATCH_NEEDED=xx1   translation needed
PATCH_NEEDED=x1x   rotation needed
PATCH_NEEDED=1xx   energy needed
PATCH_NEEDED< 0   not patch-able


 CALL  READ_AND_APPEND_VIRGIN_LAYOUT(M_U,"D:\etienne\LHC\IR11")
 reads and puts in the universe

 
 call make_node_layout(L)  makes integration_node L%t
   call FILL_SURVEY_DATA_IN_NODE_LAYOUT(L)    
   ! THIS SUBROUTINE ALLOCATES NODE FRAMES IF NEEDED   
    ! IT SURVEYS THE NODES USING THE OLD REAL WORMS    
    ! SHOULD BE CALLED AFTER MISALIGNMENTS OR MOVING PART OF LATTICE
    
    Frank
    Piotr
    Massimo
    werner
    dejan
    dmitry
    sagan
    mei
    vladimir
    david K.
    
